﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using WordWonderGame.Business;
using System.Windows.Forms;
using System.Media;

namespace WordWonderGame.UI
{
    public partial class FormMan1 : UserControl
    {

        ChonDapAnMan1UI dapAnUI;
        public event EventHandler QuaMan1Roi;
        TimerUI timerUI;
        List<CauHoiMan1> list7CauHoiMan1;
        int CauHoiHienTai;
        bool[] KetQua;
        public FormMan1()
        {

            InitializeComponent();
            dapAnUI = new ChonDapAnMan1UI();
            dapAnUI.Dock = DockStyle.Fill;
            dapAnUI.Parent = pnDapAn;
            dapAnUI.Visible = false;
            dapAnUI.ChonDung += new EventHandler(dapAnUI_ChonDung);
            dapAnUI.ChonSai += new EventHandler(dapAnUI_ChonSai);
            //TimerUI
            timerUI = new TimerUI();
            timerUI.Dock = DockStyle.Fill;
            timerUI.Parent = pnTimer;
            timerUI.Visible = false;
            timerUI.HetGio += new EventHandler(timerUI_HetGio);
            timerUI.LoadCauHoiMoi += new EventHandler(timerUI_LoadCauHoiMoi);
            //KetQua
            KetQua = new bool[7];
        }

        void timerUI_LoadCauHoiMoi(object sender, EventArgs e)
        {
            if (list7CauHoiMan1[CauHoiHienTai - 1].DapAn.Count == 1)
            {
                if (QuaMan1Roi != null)
                {
                    QuaMan1Roi(timerUI.Diem, null);
                }
            }
            else
            {
                dapAnUI.LoadDapAn(list7CauHoiMan1[CauHoiHienTai - 1].DapAn);
                timerUI.Restart();
            }
        }

        void timerUI_HetGio(object sender, EventArgs e)
        {
            timerUI.SaiCauNay(CauHoiHienTai);
            dapAnUI.HienDapAn();
            KetQua[CauHoiHienTai-1] = false;
            if (CauHoiHienTai == 7)
            {
            }
            else
            {
                CauHoiHienTai++;
            }
        }

        void dapAnUI_ChonSai(object sender, EventArgs e)
        {

            timerUI.SaiCauNay(CauHoiHienTai);
            KetQua[CauHoiHienTai - 1] = false;
            if (CauHoiHienTai == 7)
            {
            }
            else
            {
                CauHoiHienTai++;
            }
        }

        void dapAnUI_ChonDung(object sender, EventArgs e)
        {
            timerUI.DungCauNay(CauHoiHienTai);
            KetQua[CauHoiHienTai - 1] = true;
            if (CauHoiHienTai == 7)
            {
            }
            else
            {
                CauHoiHienTai++;
            }
        }

        private void FormMan1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SoundPlayer playerbutton = new SoundPlayer(@"Sound\button_click.wav");
            playerbutton.Play();
            dapAnUI.Visible = true;
            CauHoiHienTai = 0;
            list7CauHoiMan1 = new List<CauHoiMan1>();
            DataClassDAL dataClass = new DataClassDAL();
            list7CauHoiMan1 = dataClass.Lay7CauHoiMan1();
            dapAnUI.LoadDapAn(list7CauHoiMan1[CauHoiHienTai].DapAn);
            timerUI.Visible = true;
            CauHoiHienTai = 1;
            button1.Visible = false;
        }
    }
}
